<template>
  <view class="container">
    <view class="tabbar">
      <text class="tabbar-title">点一点, 领福利</text>
    </view>
    <uv-swiper
      v-if="merchantH5Info.merchantType != 2"
      :list="merchantH5Info.carouselImageList"
      keyName="imageUrl"
      circular
      :autoplay="true"
      height="320rpx"
      indicator
      indicatorMode="dot"
      interval="2000"
    ></uv-swiper>
    <view class="homeComponent">
      <newHome
        :parentMessageList="merchantH5Info.parentMessageList"
        :flag="1"
      ></newHome>
    </view>
    <view class="advertisement">
      <text>通栏广告位</text>
    </view>
  </view>
</template>

<script>
import newHome from "@/components/newHome/newHome.vue";
import { getAlternativeSuppliers, getMerchantH5Info } from "@/common/api.js";
import { toast } from "@/utils/common";
const app = getApp();
export default {
  data() {
    return {
      merchantH5Info: {
        parentMessageList: [],
        carouselImageList: [],
        merchantType: 2,
      },
    };
  },
  onLoad() {
    getAlternativeSuppliers({
      deviceCode: this.$store.state.user.deviceId,
    }).then((res) => {
      app.globalData.merchantId = res.data.id;
      this.merchantH5Info.merchantType = res.data.merchantType;
      getMerchantH5Info({
        merchantId: res.data.id,
      }).then((ress) => {
        let info = ress.data;
        // merchantH5Info
        // info.for
        let shopName = "";
        let baseList = [];
        for (var key in info) {
          switch (key) {
            case "merchantInfo":
              shopName = "商家信息";
              baseList = [
                {
                  channelLogo: "../../static/images/newHome/117.png",
                  channelName: "店长微信",
                  url: "pages/H5/qrCode",
                },
                {
                  channelLogo: "../../static/images/newHome/WIFI.png",
                  channelName: "连接WIFI",
                  url: "pages/H5/WIFI",
                },
                // {
                //   channelLogo: "../../static/images/newHome/70.png",
                //   channelName: "xcc",
                //   url: "pages/index/index",
                // },
                // {
                // 	channelLogo: '../../static/images/newHome/70.png',
                // 	channelName: 'xcc',
                // 	url: "page_account/discount/discount"
                // }
              ];
              this.$store.commit("SET_MINFO", info.merchantInfo);
              break;
            case "carouselImageList":
              this.merchantH5Info.carouselImageList = info.carouselImageList;
              break;
            // case "grassPlantingChannelList":
            //   shopName = "发视频/种草";
            //   baseList = info.grassPlantingChannelList;
            //   break;
            case "commentsChannelList":
              shopName = "打卡评论";
              baseList = info.commentsChannelList;
              break;
            case "groupBuyingChannelList":
              shopName = "商家团购";
              baseList = info.groupBuyingChannelList;
              baseList.forEach((item) => {
                switch (item.channelId) {
                  case 7:
                    //美团
                    item.path_scheme = item.merchantLinkUrl;
                    item.type = "meituan";
                    break;
                  case 8:
                    //大众
                    item.path_scheme = item.merchantLinkUrl;
                    item.type = "dianping";
                    break;
                  case 9:
                    //抖音
                    item.path_scheme = item.merchantLinkUrl;
                    item.type = "douyin";
                    break;
                }
              });
              break;
          }
          if (shopName && baseList.length > 0) {
            this.merchantH5Info.parentMessageList.push({
              shopName,
              baseList,
            });
          }
        }
        console.log(this.merchantH5Info);
      });
    });
  },
};
</script>

<style lang="scss">
.container {
  display: flex;
  min-height: 100vh;
  width: 100%;
  flex-direction: column;
  box-sizing: border-box;
  padding: 20rpx;
  background: radial-gradient(
    128% 128% at 95% 0%,
    #d7ceff 0%,
    #bbe1ff 62%,
    #ffffff 95%
  );

  .tabbar {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 220rpx;
    width: 100%;

    .tabbar-title {
      font-style: italic;
      font-weight: 900;
      font-family: YouSheBiaoTiHei, YouSheBiaoTiHei;
      color: #333333;
      line-height: 62rpx;
    }
  }

  .u-swiper {
    display: flex;
    padding: 10rpx 10rpx;
    height: 400rpx !important;
    width: 100%;
    border-radius: 0 !important;
    overflow: hidden;
    box-sizing: border-box;
    background: radial-gradient(
      128% 116% at 122% -42%,
      #d7ceff 0%,
      #bbe1ff 63%,
      #ffffff 96%
    );

    /* 确保图片在滑块中正确显示 */
    .u-swiper-item {
      overflow: hidden;
      display: flex;
      flex: 1;
      justify-content: center;
      align-items: center;
      width: 100%;
      display: inline-block;

      image {
        overflow: hidden;
        width: 100% !important;
        height: 100% !important;
        box-sizing: border-box;
        display: inline-block;
      }
    }
  }

  .homeComponent {
    height: auto;
  }

  .advertisement {
    border-radius: 48rpx;
    width: 100%;
    height: 200rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    // flex:1;
    background-color: #a9a9a9;
  }
}
</style>
